﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
namespace Efficient.DataAccess
{
    public interface IQuery
    {
        /// <summary>
        /// 执行SQL语句返回第一行第一列的数据
        /// </summary>
        /// <returns></returns>
        object ExecuteScalar();
        /// <summary>
        /// 执行非select的SQL语句返回影响的行数
        /// </summary>
        /// <returns></returns>
        int ExecuteUpdate();
        /// <summary>
        /// 执行查询语句并采用给定的实体转化器把结果转换为实体类
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <exception cref="NullReferenceException">没有设置实体转换器时抛出</exception>
        /// <returns>泛型列表</returns>
        IList<T> List<T>() where T : new();
        /// <summary>
        /// 执行查询语句并采用给定的实体转化器把结果转换为实体类
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <exception cref="NullReferenceException">没有设置实体转换器时抛出</exception>
        /// <param name="converter">实体转换器</param>
        /// <returns>泛型列表</returns>
        IList<T> List<T>(Reader2Entity<T> converter) where T : new();
        /// <summary>
        /// 返回查询结果的DataTable
        /// </summary>
        /// <returns>DataTable</returns>
        DataTable Table();
        /// <summary>
        /// 返回查询结果的DataTable
        /// </summary>
        /// <param name="name">指定表明</param>
        /// <returns></returns>
        DataTable Table(string name);
        /// <summary>
        /// 查询数据采用默认的实体转换器转为实体并且填充泛型列表
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="results">泛型列表</param>
        void List<T>(IList<T> results) where T : new();
        /// <summary>
        /// 查询数据采用指定的实体转换器转为实体并且填充泛型列表
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="converter">实体转换器</param>
        /// <param name="results">泛型列表</param>
        void List<T>(IList<T> results, Reader2Entity<T> converter) where T : new();
        /// <summary>
        /// 查询第一条数据采用默认的实体转换器转为实体
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <returns>实体类</returns>
        T UniqueResult<T>() where T : new();
        /// <summary>
        /// 查询第一条数据采用指定的实体转换器转为实体
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="converter">实体转换器</param>
        /// <returns>实体类</returns>
        T UniqueResult<T>(Reader2Entity<T> converter) where T : new();
        /// <summary>
        /// 计算当前查询语句的记录数
        /// </summary>
        /// <returns></returns>
        long ComputeRecordCount();
        /// <summary>
        /// 是否开启智能sql分页,默认是开启
        /// </summary>
        /// <param name="enable"></param>
        /// <returns></returns>
        IQuery SetEnableSqlPaging(bool enable);
        /// <summary>
        /// 设置命令类型
        /// </summary>
        /// <param name="cmdType">命令类型</param>
        /// <returns></returns>
        IQuery SetCommandType(CommandType cmdType);
        /// <summary>
        /// 设置默认的实体转换器
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="convert"></param>
        /// <returns></returns>
        IQuery SetEntityConverter<T>(Reader2Entity<T> converter) where T : new();
        /// <summary>
        /// 设置从返回记录集的那条记录开始返回
        /// </summary>
        /// <param name="firstResult"></param>
        /// <returns></returns>
        IQuery SetFirstResult(uint firstResult);
        /// <summary>
        /// 设置返回记录数
        /// </summary>
        /// <param name="maxResults"></param>
        /// <returns></returns>
        IQuery SetMaxResults(uint maxResults);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetBinary(string name, byte[] val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetBoolean(string name, bool val);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetByte(string name, byte val);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetCharacter(string name, char val);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetDateTime(string name, DateTime val);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetDecimal(string name, decimal val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetDouble(string name, double val);
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetGuid(string name, Guid val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetInt16(string name, short val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetInt32(string name, int val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetInt64(string name, long val);
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetParameter(string name, object val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="vals"></param>
        /// <returns></returns>
        IQuery SetParameterList(string name, object[] vals);
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="vals"></param>
        /// <returns></returns>
        IQuery SetParameterList<T>(string name, ICollection<T> vals);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetSingle(string name, float val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetString(string name, string val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetTime(string name, DateTime val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="val"></param>
        /// <returns></returns>
        IQuery SetTimestamp(string name, DateTime val);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="paramSet"></param>
        /// <returns></returns>
        IQuery SetQueryParameters(IEnumerable<IParameter> paramSet);
    }
}
